﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StateGrid.ZWQK
{
    class Program
    {
        static ZWQK_DAO dao = new ZWQK_DAO();

        static void Main(string[] args)
        {
            TestSelectAll();
            TestSelectSome();
            TestInsertAndDelete();
            TestQuerySome();
        }

        static void TestQuerySome()
        {
            Console.WriteLine("=====测试条件检索索引目录=====");
            TestEachSYMLQuery("", "");
            TestEachSYMLQuery("ZWHB50", "");
            TestEachSYMLQuery("", "电力");
            TestEachSYMLQuery("ZWHB50", "电力");
           
            Console.WriteLine("=====测试条件检索篇名表=====");
            //这个查询的效率要提高，请对篇名表中的"sybm"列建立索引！
            TestEachPMQuery("ZWHB10F6");
            TestEachPMQuery("ZWHD1008");
        }

        static void TestEachPMQuery(String sybm)
        {
            Console.WriteLine("-----索引编码：" + sybm);
            int resultCount = dao.countQueryZwqkPM(sybm);
            Console.WriteLine("结果数目：" + resultCount);
            if (resultCount > 0)
            {
                foreach (ZWQK_PM pm in dao.queryZwqkPM(sybm, 0, 5))
                    Console.WriteLine("结果示例：" + pm.outputString4Test());
            }
        }

        static void TestEachSYMLQuery(String flbm, String zwmc)
        {
            Console.WriteLine("-----分类编码："+flbm+"，中文名称："+zwmc+"-----");
            int resultCount = dao.countQueryZwqkSYML(flbm, zwmc);
            Console.WriteLine("结果数目："+resultCount);
            if (resultCount>0) {
                foreach (ZWQK_SYML ml in dao.queryZwqkSYML(flbm, zwmc, 0, 5)) 
                {
                    Console.WriteLine("结果示例：" + ml.flbm + " " + ml.zwmc);
                }
            }
        }

        static void TestSelectAll() 
        {
            Console.WriteLine("获取全部：");
            IList<ZWQK_FL> allFL = dao.getAllZwqkFL();
            Console.WriteLine(allFL.Count);
            Console.WriteLine(allFL[0].outputString4Test());
            IList<ZWQK_SYML> allSyml = dao.getAllZwqkSYML();
            Console.WriteLine(allSyml.Count);
            Console.WriteLine(allSyml[0].outputString4Test());
            IList<ZWQK_PM> allPM = dao.getAllZwqkPM();
            Console.WriteLine(allPM.Count);
            Console.WriteLine(allPM[0].outputString4Test());
        }

        static void TestSelectSome()
        {
            Console.WriteLine("获取部分：");
            IList<ZWQK_FL> someFL = dao.getSomeZwqkFL(1, 20);
            Console.WriteLine(someFL.Count);
            IList<ZWQK_SYML> someSyml = dao.getSomeZwqkSYML(1, 20);
            Console.WriteLine(someSyml.Count);
            IList<ZWQK_PM> somePM = dao.getSomeZwqkPM(1, 20);
            Console.WriteLine(somePM.Count);
        }

        static void TestInsertAndDelete()
        {
            ZWQK_FL newFL = new ZWQK_FL();
            newFL.flbm = "AAA";
            newFL.flmc = "测试A";
            newFL.flsm = "无";
            Console.WriteLine("插入...");
            dao.insertZwqkFL(newFL);
            newFL  = dao.getZwqkFLByFlbm("AAA");
            Console.WriteLine(newFL.outputString4Test());
            Console.WriteLine("删除...");
            dao.deleteZwqkFLByFlbm("AAA");
            newFL = dao.getZwqkFLByFlbm("AAA");
            if (newFL == null)
                Console.WriteLine("删除成功");
            else
                Console.WriteLine("删除失败");

            ZWQK_SYML newSYML = new ZWQK_SYML();
            newSYML.flbm = "AAA";
            newSYML.sybm = "SYBM";
            newSYML.zwmc = "测试索引";
            Console.WriteLine("插入...");
            dao.insertZwqkSYML(newSYML);
            newSYML = dao.getZwqkSYMLBySybm("SYBM");
            Console.WriteLine(newSYML.outputString4Test());
            Console.WriteLine("删除...");
            dao.deleteZwqkSYMLBySybm("SYBM");
            newSYML = dao.getZwqkSYMLBySybm("SYBM");
            if (newSYML == null)
                Console.WriteLine("删除成功");
            else
                Console.WriteLine("删除失败");

            ZWQK_PM newPM = new ZWQK_PM();
            newPM.wjm = "filename.pdf";
            newPM.sybm = "SYBM";
            newPM.zwpm = "测试篇名";
            newPM.gxrq = DateTime.Now;
            Console.WriteLine("插入...");
            dao.insertAndLogZwqkPM(newPM,"SINGLE");
            newPM = dao.getZwqkPMByWjm("filename.pdf");
            Console.WriteLine(newPM.outputString4Test());
            Console.WriteLine("修改篇名...");
            dao.changeZwqkPMWjm("filename.pdf", "filenamenew.pdf");
            newPM = dao.getZwqkPMByWjm("filenamenew.pdf");
            Console.WriteLine(newPM.outputString4Test());
            Console.WriteLine("删除...");
            dao.deleteZwqkPMByWjm("filenamenew.pdf");
            newPM = dao.getZwqkPMByWjm("filenamenew.pdf");
            if (newPM == null)
                Console.WriteLine("删除成功");
            else
                Console.WriteLine("删除失败");

        }
    }
}
